<?php

$date = $_GET["date"];
$yesterday = $_GET["yesterday"];
$openid = $_GET["openid"];

$conn = mysqli_connect("localhost", "root", "", "cloudwarehouse");

if (!$conn)
    echo "数据库连接失败！";
else {
    $sql_getprofit ="SELECT sum(profit) FROM commodity_profit WHERE outboundDate = '$date' AND openid = '$openid'";
    $result_getprofit = mysqli_query($conn,$sql_getprofit);  

    $profit_pre = mysqli_fetch_array($result_getprofit);                   
    //  echo $profit_pre[0];                 //利润
    if($profit_pre[0] == NULL){
        $profit = 0;}
    else {
        $profit = round($profit_pre[0],2);}
    


    $sql_getprofit_yes ="SELECT sum(profit) FROM commodity_profit WHERE outboundDate = '$yesterday' AND openid = '$openid'";
    $result_getprofit_yes = mysqli_query($conn,$sql_getprofit_yes);

    $profit_yes = mysqli_fetch_array($result_getprofit_yes); 
  //  echo $profit[0];
   // echo $profit_yes[0];   //相比昨天
    $cha = round($profit - $profit_yes[0],2);


    $sql_case ="SELECT sum(outboundTotalprice) FROM outboundlist WHERE outboundDate = '$date' AND openid = '$openid'";
    $result_case = mysqli_query($conn,$sql_case);  

    $case_pre = mysqli_fetch_array($result_case);                   
    // echo $case[0];                   //销售额
    if($case_pre[0] == NULL){
        $case = 0;}
    else {
        $case = round($case_pre[0],2);}

    echo $array = json_encode(array( $profit,$cha,$case));

}
?>